/*====================================================================*
 *
 *   Copyright (c) 2011, 2012, Qualcomm Atheros Communications Inc.
 *
 *   Permission to use, copy, modify, and/or distribute this software
 *   for any purpose with or without fee is hereby granted, provided
 *   that the above copyright notice and this permission notice appear
 *   in all copies.
 *
 *   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
 *   WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
 *   WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
 *   THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
 *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 *   LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 *   NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 *   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 *--------------------------------------------------------------------*/

/*====================================================================*
 *
 *   qca_7k.c	-
 *
 *   This module implements the Qualcomm Atheros SPI protocol for
 *   kernel-based SPI device.
 *
 *--------------------------------------------------------------------*/

/*====================================================================*
 *   system header files;
 *--------------------------------------------------------------------*/

/*====================================================================*
 *   custom header files;
 *--------------------------------------------------------------------*/

#include "qca_7k.h"
#include "byte_order.h"
#include "spi.h"
#include "FreeRTOS.h"
#include "queue.h"
#include "semphr.h"
#include "task.h"
uint16_t qcaspi_read_register(qcaspi_t *qca, uint16_t reg)
{
    uint16_t rx_data = {0};
    uint16_t tx_data=__cpu_to_be16(QCA7K_SPI_READ | QCA7K_SPI_INTERNAL | reg);
    HAL_SPI_TransmitReceive_DMA(&hspi1,(uint8_t *)&tx_data,(uint8_t *)&rx_data,2);
    ulTaskNotifyTake(pdTRUE, -1);
    return __be16_to_cpu(rx_data);
}

void qcaspi_write_register(qcaspi_t *qca, uint16_t reg, uint16_t value)
{
    uint16_t tx_data[2];
    tx_data[0]  = __cpu_to_be16(QCA7K_SPI_WRITE | QCA7K_SPI_INTERNAL | reg);
    tx_data[1] = __cpu_to_be16(value);
    ulTaskNotifyTake(pdTRUE, -1);
    HAL_SPI_Transmit_DMA(&hspi1,(uint8_t *)&tx_data,4);
}
